﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace badminton.Controls
{
    public partial class BulletinBoard : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindTrainInfo();
            }
        }

        protected void bindTrainInfo()
        {
            BadmintonEntities bde = new BadmintonEntities();
            
            Repeater1.DataSource = bde.Training.OrderByDescending(p=>p.startTime).Take(10);
            Repeater1.DataBind();

        }


        public string GetURL(object id)
        {
            int tid = (int)id;
            return "~/Pages/TrainingDetail.aspx?trainingid=" + tid.ToString();

        }

        public string GetText(object id)
        {
            int tid = (int)id;
            BadmintonEntities bde = new BadmintonEntities();
            Training training = bde.Training.FirstOrDefault(p => p.id == tid);
            if (training != null)
            {
                return training.name;
            }
            return "";
        }

        public string GetHallName(object id)
        {
            int tid = (int)id;
            BadmintonEntities bde = new BadmintonEntities();
            Training training = bde.Training.FirstOrDefault(p => p.id == tid);
            if (training != null && training.Hall != null)
            {
                return training.Hall.name;
            }
            return "";
        }

        public string GetStartTime(object id)
        {
            int tid = (int)id;
            BadmintonEntities bde = new BadmintonEntities();
            Training training = bde.Training.FirstOrDefault(p => p.id == tid);
            if (training != null && training.startTime != null)
            {
                return training.startTime.GetValueOrDefault().ToString("yyyy.MM.dd");
            }
            return "";
        }
    }
}